package com.scy.edu.server;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author 司晨雨
 * @date 2020/6/28 21:06
 * @description
 */
public class Request {

    private String method; //请求方式 GET/POST

    private String url;

    private InputStream inputStream; //输入流，其他属性从从输入流中解析出来

    private String host;

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public InputStream getInputStream() {
        return inputStream;
    }

    public void setInputStream(InputStream inputStream) {
        this.inputStream = inputStream;
    }

    public Request() {
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public Request(InputStream inputStream) throws IOException {
        this.inputStream = inputStream;
        int count = 0;
        while (count == 0){
            count = inputStream.available();
        }
        byte[] bytes = new byte[count];
        inputStream.read(bytes);
        String inputStr = new String(bytes);
        String firstLineStr = inputStr.split("\\n")[0]; //GET / HTTP/1.1
        String[] strings = firstLineStr.split(" ");
        this.method = strings[0];
        this.url = strings[1];
    }

}
